public class LLStack {
    LLNode headNode = null;

    public LLStack() {
        this.headNode = new LLNode(null);
    }

    boolean isEmpty(){
        return headNode == null;
    }

    /**
     * 压栈
     * @param data
     */
    void push(Object data){
        if(headNode == null){
            headNode = new LLNode(0);
        }else if(headNode.getData() == null){
            headNode.setData(data);
        }else{
            LLNode llNode = new LLNode(data);
            llNode.setNext(headNode);
            headNode = llNode;
        }
    }

    /**
     * 出栈
     * @return data
     */
    Object pop(){
        if(isEmpty()){
            System.out.println("栈内为空，无法出栈");
            return 0;
        }else{
            Object data = headNode.getData();
            headNode = headNode.getNext();
            return data;
        }
    }

    /**
     * 返回栈顶的值
     * @return：头结点的值
     */
    Object top(){
        Object data = null;
        if(isEmpty()){
            System.out.println("栈为空");
            return 0;
        }else{
            data =headNode.getData();
            return data;
        }
    }
}

class LLNode{
    Object data;
    LLNode next;

    public LLNode(Object data) {
        this.data = data;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public LLNode getNext() {
        return next;
    }

    public void setNext(LLNode next) {
        this.next = next;
    }
}


